package controller;

import core.BaseServlet;
import service.ForegroundService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 前台系统
 */
@WebServlet(name = "ForegroundServlet", urlPatterns = "/foreground")
public class ForegroundServlet extends BaseServlet {

    private ForegroundService foregroundService = new ForegroundService();

    /**
     * 会员注册界面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void memberRegisterPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foreground/register/memberRegister.jsp").forward(request, response);
    }


    /**
     * 会员注册
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void memberRegister(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.memberRegister(request, response);
    }

    /**
     * 会员充值界面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void memberRechargePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getSession().removeAttribute("registerMember");
        request.getRequestDispatcher("/WEB-INF/pages/foreground/recharge/memberRecharge.jsp").forward(request, response);
    }

    /**
     * 从注册页面跳转至会员充值界面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void memberRechargePageFromRegister(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foreground/recharge/memberRecharge.jsp").forward(request, response);
    }

    /**
     * 查找会员
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findMember(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.findMember(request, response);
    }

    /**
     * 充值
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void recharge(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.recharge(request, response);
    }

    /**
     * 开台
     * @param request
     * @param response
     */
    public void setUpTable(HttpServletRequest request, HttpServletResponse response){
        foregroundService.setUpTable(request, response);
    }

    /**
     * 开台页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void setUpTablePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foreground/foregroundSystem/setUpTablePage.jsp").forward(request, response);
    }

    /**
     * 前台系统界面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void foregroundSystemPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.tableList(request, response);
    }

    /**
     * 预定餐桌界面界面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void bookTablePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foreground/foregroundSystem/bookTablePage.jsp").forward(request, response);
    }

    /**
     * 预定餐桌
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void bookTable(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       foregroundService.bookTable(request, response);
    }

    /**
     * 取消预定餐桌
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void cancelBookTable(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       foregroundService.cancelBookTable(request, response);
    }

    /**
     * 点单页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void orderPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foreground/foregroundSystem/order.jsp").forward(request, response);
    }

    /**
     * 点单页面获取所有可用的菜品类型
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findAllFoodTypeInUse(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.findAllFoodTypeInUse(request, response);
    }

    /**
     * 点单页面获取所有可用的菜品
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findAllFood(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.findAllFood(request, response);
    }

    /**
     * 点单页面获取所有可用的菜品
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findFoodListByParam(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.findFoodListByParam(request, response);
    }

    /**
     * 点单页面添加订单菜品
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void addOrderFood(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.addOrderFood(request, response);
    }

    /**
     * 获取餐桌的餐桌信息
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findOrderFoodByOrderID(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.findOrderFoodByOrderID(request, response);
    }

    /**
     * 获取餐桌的餐桌信息
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findOrderIdByTableID(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.findOrderIdByTableID(request, response);
    }

    /**
     * 购物车页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void cartPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foreground/foregroundSystem/cart.jsp").forward(request, response);
    }

    /**
     * 通过订单id查找订单
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findOrderByTableId(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.findOrderByTableId(request, response);
    }

    /**
     * 删除订单中的食品
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void deleteOrderFood(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.deleteOrderFood(request, response);
    }

    /**
     * 减少一份订单中的食品
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void subOrderFood(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.subOrderFood(request, response);
    }

    /**
     * 提交订单
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void submitOrder(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.submitOrder(request, response);
    }

    /**
     * 支付订单
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void payPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.payPage(request, response);
    }

    /**
     * 通过Id查找员工
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void findWorkerById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.findWorkerById(request, response);
    }
    /**
     * 支付类型选择页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void payChoicePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foreground/foregroundSystem/payChoice.jsp").forward(request, response);
    }

    /**
     * 非会员支付页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void normalPayPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foreground/foregroundSystem/normalPay.jsp").forward(request, response);
    }

    /**
     * 非会员支付
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void normalPay(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.normalPay(request, response);
    }


    /**
     * 会员支付页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void memberPayPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foreground/foregroundSystem/memberPay.jsp").forward(request, response);
    }

    /**
     * 会员余额支付
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void memberPay(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.memberPay(request, response);
    }

    /**
     * 会员非余额支付
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void memberNormalPay(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foregroundService.memberNormalPay(request, response);
    }
}
